var app = angular.module("myApp",[]);
app.controller("myCtrl",function($scope,$http){
	$scope.reminder = false;             //提示框
	$scope.close = function(){
		$scope.reminder = false;
	}
	
	$scope.idCard = "";
	$scope.gender = "";
	$scope.username = "";
	$scope.mobile = "";
	$scope.email = "";
	$scope.birthday = "";
	
	$http({
	    method : "post",
	    dataType: "json",
		withCredentials: true,	//跨域名请求。XHR：XMLHttpRequest (XHR) ，基于XML技术的Http请求
		crossDomain: true,
		headers:{'Content-Type': 'application/x-www-form-urlencoded'},
	    async:true,
	    url : host + "/terminal/user/detail"
	}).success(function(response){
		if(response.code == 2000){
			console.log(response.data.user);
			$scope.idCard = response.data.user.idCard;
			$scope.gender = response.data.user.gender;
			$scope.username = response.data.user.username;
			$scope.mobile = response.data.user.mobile;
			$scope.email = response.data.user.email;
			$scope.birthday = response.data.user.birthday;
			switch($scope.gender){
				case "男" : 
				    $scope.a = true;
					$scope.b = false;
					break;
				case "女" :
				    $scope.a = false;
					$scope.b = true;
			}
		}
		if(response.code == 4003){
			$scope.reminder = true; 
			$scope.message = response.message;
		}
	})
	
	$scope.active0 = function(){
		$scope.a = true;
		$scope.b = false;
		$scope.gender = "男";
	}
	$scope.active1 = function(){
		$scope.a = false;
		$scope.b = true;
		$scope.gender = "女";
	}
	
	$scope.change = function(){
		var params={
			username:$scope.username,
			mobile:$scope.mobile,
			email:$scope.email,
			gender:$scope.gender
		}
		params = $.param(params);
		$http({
        	method : "post",
        	dataType: "json",
			withCredentials: true,	//跨域名请求。XHR：XMLHttpRequest (XHR) ，基于XML技术的Http请求
	        headers:{'Content-Type': 'application/x-www-form-urlencoded'},
	        crossDomain: true,
	        data : params,
        	url : host + "/terminal/user/update"
       }).success(function(response){
       	console.log(response);
        	if(response.code == 2000){
        		$scope.reminder = true; 
				$scope.message = response.message;
        	}
        	if(response.code == 4003){
        		$scope.reminder = true; 
				$scope.message = response.message;
        	}
        })
	}
})